package com.rla.controller;

import java.util.List;
import java.util.Arrays;
import java.util.Map;

import com.rla.domain.bo.EhsEverydayBloodGlucoseBo;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.rla.common.annotation.RepeatSubmit;
import com.rla.common.annotation.Log;
import com.rla.common.core.controller.BaseController;
import com.rla.common.core.domain.PageQuery;
import com.rla.common.core.domain.R;
import com.rla.common.utils.validate.AddGroup;
import com.rla.common.utils.validate.EditGroup;
import com.rla.common.enums.BusinessType;
import com.rla.common.utils.poi.ExcelUtil;
import com.rla.domain.vo.EhsEverydayBloodPressureVo;
import com.rla.domain.bo.EhsEverydayBloodPressureBo;
import com.rla.service.IEhsEverydayBloodPressureService;
import com.rla.common.core.page.TableDataInfo;

/**
 * 日常记录-血压记录
 *
 * @author rla
 * @date 2025-09-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/every/bloodPressure")
public class EhsEverydayBloodPressureController extends BaseController {

    private final IEhsEverydayBloodPressureService iEhsEverydayBloodPressureService;

    /**
     * 查询日常记录-血压记录列表
     */
    @GetMapping("/list")
    public TableDataInfo<EhsEverydayBloodPressureVo> list(EhsEverydayBloodPressureBo bo, PageQuery pageQuery) {
        return iEhsEverydayBloodPressureService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出日常记录-血压记录列表
     */
    @Log(title = "日常记录-血压记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(EhsEverydayBloodPressureBo bo, HttpServletResponse response) {
        List<EhsEverydayBloodPressureVo> list = iEhsEverydayBloodPressureService.queryList(bo);
        ExcelUtil.exportExcel(list, "日常记录-血压记录", EhsEverydayBloodPressureVo.class, response);
    }

    /**
     * 获取日常记录-血压记录详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<EhsEverydayBloodPressureVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iEhsEverydayBloodPressureService.queryById(id));
    }

    /**
     * 新增日常记录-血压记录
     */
    @Log(title = "日常记录-血压记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<String> add(@Validated(AddGroup.class) @RequestBody EhsEverydayBloodPressureBo bo) {
        return R.ok(iEhsEverydayBloodPressureService.insertByBo(bo));
    }

    /**
     * 修改日常记录-血压记录
     */
    @Log(title = "日常记录-血压记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody EhsEverydayBloodPressureBo bo) {
        return toAjax(iEhsEverydayBloodPressureService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除日常记录-血压记录
     *
     * @param ids 主键串
     */
    @Log(title = "日常记录-血压记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iEhsEverydayBloodPressureService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }


    /**
     * 计算当前测量数据，与上一次和10天前的数据对比
     *
     * @param id 主键
     */
    @GetMapping("/dateCompare/{id}")
    public R<Map<String,Object>> queryDateCompare(@NotNull(message = "主键不能为空")
                                                  @PathVariable String id) {
        return R.ok(iEhsEverydayBloodPressureService.queryDateCompare(id));
    }

    /**
     * 血压趋势正常异常数量统计
     */
    @GetMapping("/app/statisticsExce")
    public R<Map<String,Object>>  statisticsExce(EhsEverydayBloodGlucoseBo bo) {
        return R.ok(iEhsEverydayBloodPressureService.statisticsExce(bo));
    }

    @GetMapping("/app/trend/list")
    public R<List<Map<String,Object>>>  queryTrendList(EhsEverydayBloodPressureBo bo) {
        return R.ok(iEhsEverydayBloodPressureService.queryTrendList(bo));
    }

    /*
     * 血压健康报告
     * */
    @PostMapping("/health/report")
    public R<Map<String,Object>> healthReport(@RequestBody EhsEverydayBloodPressureBo bo) {
        return R.ok(iEhsEverydayBloodPressureService.healthReport(bo));
    }

}
